import { observable, action, autorun, toJS } from 'mobx';
import { WeaLocaleProvider,WeaLoadingGlobal  } from 'ecCom';
import {WeaForm, WeaTableNew} from 'comsMobx'
import {message, Button } from "antd";
import * as Apis from '../../apis/infoWord';
import { ListStore } from '../listStore';
import {Text} from '../../components/util/text';
const text = new Text();
const {TableStore} = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;
export default class infoCreateNotifStore extends ListStore {
    constructor(props) {
        super(props);
    }
    @observable selectedKey = 0;
    @observable dateValue = "";
    @observable responseData = {};
    @observable status = {
        disabled1:false,
        disabled2:true,
        disabled3:true,
        disabled4:true,
        loading :false
    }
    @observable tnjcurl = "";
    @observable szyxxxurl = "";

    setState = (params = {}) => {
        Object.keys(params).forEach(o => {
            this.status[o] = params[o];
        })
        return this;
    }

    @action
    setSelectedKey=(key)=>{
        this.selectedKey=key;
        if(this.selectedKey==1){
            jQuery('#info_tbList_iframe').attr('src', this.tnjcurl +"&dateValue="+this.dateValue);
        }
        if(this.selectedKey==2){
            jQuery('#info_yxList_iframe').attr('src', this.szyxxxurl +"&dateValue="+this.dateValue);
        }
    }
   
    @action
    doHandleDate = () => {
        var myDate = new Date();
        var tYear = myDate.getFullYear();
        var tMonth = myDate.getMonth();
        var m = tMonth + 1;
        if (m.toString().length == 1) {
            m = "0" + m;
        }
        let  dateValue= tYear +'-'+ m;
        this.changeDateSelect(dateValue);
    }
    @action
    toNextStep = (key) => {
        console.log("key",key);
        this.setSelectedKey(parseInt(key)+1);
        if(this.selectedKey==1){
            this.setState({disabled1:false});
        }
        if(this.selectedKey==2){
            this.setState({disabled1:false});
            this.setState({disabled2:false});
            this.setState({disabled3:false});
            this.setState({disabled4:false});
        }
    }
    //改变日期值
    @action
    changeDateSelect=(v)=>{
        this.dateValue = v;
        this.setState({disabled1:false});
        this.setState({disabled2:true});
        this.setState({disabled3:true});
        this.setState({disabled4:true});
        jQuery('#info_tbList_iframe').attr('src', "");
        jQuery('#info_yxList_iframe').attr('src', "");
    }
    /**
     * 生成通报
     */
    @action
    createNotification =()=>{
        const params={'date':this.dateValue};
        WeaLoadingGlobal.start({
            tip:<div style={{fontSize:"20px"}}>正在生成通报数据...<br/>窗体关闭前请勿做任何操作</div>, // 自定义tip文字
            size:'large'
          });;
        Apis.createNotification(params).then(data=>{
            if(data.api_status == '1'){
                if(data.ReplaceBookmarkAfterImageFileId && data.ReplaceBookmarkAfterImageFileId > 0){
                    message.success("生成通报成功");
                    // window.open("/weaver/weaver.file.FileDownload?fileid="+data.ReplaceBookmarkAfterImageFileId);
                    WeaLoadingGlobal.destroy();
                }else{
                    message.error("生成通报错误");
                    WeaLoadingGlobal.destroy();
                }
            }else{
                message.error("生成通报错误");
                WeaLoadingGlobal.destroy();
            }
        })
    }
    /**
     * 获取通报检查查询页面地址，设置优秀信息查询页面地址
     */
    @action
    getModeSearchUrl =()=>{
        Apis.getModeSearchUrl().then(data=>{
            if(data.api_status == '1'){
                this.tnjcurl = data.tnjcurl;
                this.szyxxxurl = data.szyxxxurl;
                WeaLoadingGlobal.destroy();
            }else{
                message.error("获取通报检查/设置优秀信息页面接口错误");
                WeaLoadingGlobal.destroy();
            }
        })
    }

}